package com.maniu.serialportnative;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.TextView;

import com.maniu.serialportnative.databinding.ActivityMainBinding;

import java.io.File;

public class MainActivity extends AppCompatActivity {

    // Used to load the 'serialportnative' library on application startup.
    static {
        System.loadLibrary("serialportnative");
    }

    private ActivityMainBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        binding = ActivityMainBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        // Example of a call to a native method

        SerialPort serialPort = new SerialPort(new File("/dev/ttys"));
        serialPort.getFileOutputStream();
//        serialPort.getFileOutputStream().write(new byte[0xFF, 0xFB]);
        TextView tv = binding.sampleText;
        tv.setText(stringFromJNI());
    }

    /**
     * A native method that is implemented by the 'serialportnative' native library,
     * which is packaged with this application.
     */
    public native String stringFromJNI();
}